﻿using System.Linq;
using Microsoft.Practices.Unity;

namespace Soul.Request.Core
{
    class RequestCenter : IRequestCenter
    {
        private ParallelQuery<IRequestHandler> handlers;

        public RequestCenter(IUnityContainer container)
        {
            this.handlers = container.ResolveAll<IRequestHandler>().AsParallel();
        }

        #region IRequestCenter 成员

        public void Push(RequestContext context)
        {
            var hs = this.handlers.Where(h => h.CanProcess(context));
            this.handlers.ForAll(h => h.ProcessRequest(context));
        }

        #endregion
    }
}
